import { DEBUG } from "cc/env";
import { AppConst } from "../const/Const";
import { appConfig } from "../model/appConfig";
import { Debug } from "../utils/Debug";

export class platformConf {

    private static currentConf: appConfig;
    public static get config(): appConfig {
        return this.currentConf;
    }
    public static set config(value: appConfig) {
        this.currentConf = value
    }

    private static mPlatform: AppConst
    /**
     * 获取当前的运行平台
     * PC状态下会返回debug平台
     * debug没有时 默认返回微信平台
     */
    public static get currentApp(): AppConst {
        var g = window as any;
        if (this.mPlatform) {
            return this.mPlatform;
        }
        // if (DEBUG) {
        //     this.mPlatform = AppConst.BYTEDANCE;
        // }
        else if (g['tt'])
            this.mPlatform = AppConst.BYTEDANCE
        else if (g['swan'])
            this.mPlatform = AppConst.BAIDU
        else if (g['qq'])
            this.mPlatform = AppConst.QQ
        else if (g['hbs'])
            this.mPlatform = AppConst.HW
        else if (g['qg']) {
            if (g["qg"] && g["qg"].getSystemInfoSync) {
                let sys = g["qg"].getSystemInfoSync();
                Debug.log('平台判断', JSON.stringify(sys));
                if (sys && sys.brand && sys.brand.toLocaleLowerCase().indexOf("vivo") != -1) {
                    this.mPlatform = AppConst.VIVO;
                }
                else {
                    this.mPlatform = AppConst.OPPO
                }
            }
            else {
                this.mPlatform = AppConst.OPPO
            }

        }
        else if (g['uc'])
            this.mPlatform = AppConst.UC
        else if (g['kwaigame'])
            this.mPlatform = AppConst.KUAI
        else if (g['wx'])
            this.mPlatform = AppConst.WX
        else {
            this.mPlatform = AppConst.WEB
        }
        return this.mPlatform;

    }

}